<div class="container-fluid">
  <div class="row">

    <div class="col-sm-2">
      <%= render "shared/sidenav" %>
    </div>

    <div class="col-sm-10">

      <div class="panel panel-primary filterable">
        <div class="panel-heading">
          <% if teacher_logged_in? %><h3 class="panel-title">授课列表</h3>
          <% end %>
          <% if student_logged_in? %><h3 class="panel-title">已选课程</h3>
          <% end %>
        </div>

        <div class="panel-body">
          <table class="table table-responsive table-condensed table-hover">
            <thead>
            <tr>
              <th>课程编号</th>
              <th>课程名称</th>
              <th>课时/学分</th>
              <th>上课时间</th>
              <th>周次</th>
              <th>考试方式</th>
              <th>主讲教师</th>
            </tr>

            <tbody>
            <% @course.each do |course| %>
                <tr>

                  <td><%= course.course_code %></td>
                  <td><%= link_to course.name, course_outline_course_url(course) %></td>
                  <td><%= course.credit %></td>
                  <td><%= course.course_time %></td>
                  <td><%= course.course_week %></td>
                  <td><%= course.exam_type %></td>
                  <td><%= course.teacher&.name %></td>

                  <% if teacher_logged_in? %>
                      <td>
                        <% if teacher_logged_in? %>
                            <%= link_to "学生信息", student_list_course_url(course) %>
                        <% end %>
                      </td>
                      <td><%= link_to "编辑", edit_course_url(course), class: 'btn btn-xs btn-info' %></td>
                      <% if course.open? %>
                          <td><%= link_to "关闭", close_course_url(course), class: 'btn btn-xs btn-info' %></td>
                      <% else %>
                          <td><%= link_to "开通", open_course_url(course), class: 'btn btn-xs btn-info' %></td>
                      <% end %>
                      <td><%= link_to "删除", course_path(course), :method => "delete", class: 'btn btn-xs btn-danger', :data => {confirm: '确定要删除此课程?'} %></td>
                  <% elsif student_logged_in? %>
                      <td><%= link_to "删除", quit_course_path(course), class: 'btn-sm btn-danger' %></td>
                  <% end %>
                </tr>
            <% end %>
            </tbody>
          </table>
          <%= will_paginate @course %>
        </div>
      </div>
    </div>
  </div>
</div>
<% if student_logged_in? %>
    <%= render 'courses/credits_statistics' %>
<% end %>